package pro.cherish.knowledgedemoioc.thread;

import lombok.AllArgsConstructor;
import lombok.Data;
import pro.cherish.knowledgedemoioc.service.UserService;
import pro.cherish.knowledgedemoioc.util.SpringExtensionHelper;

import javax.annotation.Resource;
import java.util.concurrent.Callable;

/**
 * @author 创建人：cherish
 * @version 版本号：V1.0
 * <p>
 * ***************************修订记录************************************
 * 2019-09-28 cherish 创建该类功能。
 * **********************************************************************
 * </p>
 * @ClassName 类名：HiThreadHandler
 * @Description 功能说明：使用工具类统一将注解配置的Bean注入，这个注入是使用spring util工具，从容器中获取bean赋值
 * <p>
 * TODO
 * </p>
 * **********************************************************************
 * @date 创建日期： 2019-09-28 cherish
 */
@Data
@AllArgsConstructor
public class HiThreadHandler implements Callable {


    private static HiThreadHandler INSTANCE;

    @Resource
    public UserService userService;

    public HiThreadHandler() {
        SpringExtensionHelper.initAutowireFields(this);
    }

    public static HiThreadHandler getInstance() {
        if (INSTANCE == null) {
            INSTANCE = new HiThreadHandler();
            return INSTANCE;
        } else {
            return INSTANCE;
        }
    }


    @Override
    public Object call() throws Exception {
        Object user = userService.getUser();
        System.out.println(user);
        System.out.println("线程" + Thread.currentThread().getName() + "调用了，获取到了name " + user);
        return "我知道了";
    }
}
